<?php
/*
 * 视频
 * @author  zhanghui
 * @create_date 2008-02-27
 */

class Video{
    function __construct(){}
    
    function __destruct(){}
    
    /* 增加视频  
     * @param : $arr_input -  baby_id,folderid,postid,title,comment,tag,active_type,create_date
     */
    public function addVideo($conn,$arr_input){
        $str_query = "insert into";
        $str_query .= " baby_video";
        $str_query .= " set";
        $str_query .= " baby_id={$arr_input['baby_id']}";
        $str_query .= ",folderid={$arr_input['folderid']}";
        $str_query .= ",title='{$arr_input['title']}'";
        $str_query .= ",comment='{$arr_input['comment']}'";
        $str_query .= ",tag='{$arr_input['tag']}'";
        $str_query .= ",active_type={$arr_input['active_type']}";
        $str_query .= ",create_date='".$conn->getCurrentTime()."'";
        
        $conn->executeQuery($str_query);
        
        $obj_VideoCnt = new VideoCnt();
        $obj_VideoCnt->initVideoCnt($conn,$arr_input);
    }
    
    /* 视频编辑
     *@param : $arr_input -  baby_id,folderid,postid,title,comment,tag,active_type,create_date
    */
    public function editVideo($conn,$arr_input){
    	$str_query = "update";
    	$str_query .= " baby_video";
    	$str_query .= " set";
        $str_query .= " title='{$arr_input['title']}'";
        $str_query .= ",comment='{$arr_input['comment']}'";
        $str_query .= ",tag='{$arr_input['tag']}'";
        $str_query .= ",active_type={$arr_input['active_type']}";
        $str_query .= " where";
        $str_query .= " baby_id = {$arr_input['baby_id']}";
        $str_query .= " and folderid = {$arr_input['folderid']}";
        $str_query .= " and postid = {$arr_input['postid']}";
        
        $conn->executeQuery($str_query);
    }
    
    /* 删除视频
     * @param : $arr_input -  baby_id,postid,title,comment,tag,active_type,create_date
    */
    public function deleteVideo($conn,$arr_input){
    	$str_query = "delete from";
    	$str_query .= " baby_video";
    	$str_query .= " where";
    	$str_query .= " baby_id={$arr_input['baby_id']}";
    	$str_query .= " and folderid={$arr_input['folderid']}";
    	
    	if(isset($arr_input['postid'])){
    		$str_query .= " and postid={$arr_input['postid']}";  		
    	}
    		$conn->executeQuery($str_query);
    	
    	    $obj_VideoComment = new VideoComment();
    	    $obj_VideoComment->deleteComment($conn,$arr_input);
    	
    	
    	
    }
    
    /* 获取视频
     * @param : $arr_input - $arr_input - baby_id,folderid,postid,title,comment,tag,active_type,create_date
     * @return : $arr_output 
     *           baby_id,             [0]<br>
     *		     folderid,            [1]<br>
     *           postid,              [2]<br>
     *           title,               [3]<br>
     *           content,             [4]<br>
     *           ip_address,          [5]<br>
     *           diary_date,          [6]<br>
     *           weatherid,           [7]<br>
     *           emoticonid,          [8]<br>
     *           create_date,         [9]<br>
     *           update_date,         [10]<br>
    */
    public function getVideoList($conn,$arr_input,$limit = null){
    	$str_query = "select";
    	if(isset($arr_input['cnt'])){
    		$str_query .= " count(1)";
    	}else{
    		$str_query .= " baby_id";
    		$str_query .= " ,folderid";
    		$str_query .= " ,postid";
    		$str_query .= " ,title";
    		$str_query .= " ,content";
    		$str_query .= " ,ip_address";
    		$str_query .= " ,diary_date";
    		$str_query .= " ,weatherid";
    		$str_query .= " ,emoticonid";
    		$str_query .= " ,create_date";
    		$str_query .= " ,update_date";
    	}
    	$str_query .=" from";
    	$str_query .=" baby_video";
    	$str_query .=" where";
    	$str_query .=" baby_id={$arr_input['baby_id']}";
    	
    	if(isset($arr_input['folderid'])){
    		$str_query .=" and folderid={$arr_input['folderid']}";
    	}
    	if(isset($arr_input['postid'])){
    		$str_query .=" and postid={$arr_input['postid']}";
    	}
    	if (isset($arr_input['orderby'])) {
    		$str_query .= " order by {$arr_input['orderby']}";
    	}
    	if ($limit != null){
    		$str_query .= " {$limit}";
    	}

    	$arr_output = $conn->selectQuery($str_query);
    	return $arr_output;
    }
}
?>